<link rel="stylesheet" type="text/css" href="<?= base_url() ?>file/js/easyui/themes/gray/easyui.css">
<link rel="stylesheet" type="text/css" href="<?= base_url() ?>file/js/easyui/themes/icon.css">

<script type="text/javascript" src="<?= base_url() ?>file/js/add-item.js"></script>


<form id="form" action="<?=$_SERVER['PHP_SELF']?>" method="post">
<div class="panel-wrap" style="height: auto">
	<div class="panel-header-div">Cluster Information</div>
    <div class="panel-body-div">
    
        <div class="left-panel-body">
        <input type="hidden" id="checkson" value="test"/>
        <!--<div id="textis" style="float: left; width: 100px; height: 100px; background-color: aqua;">
        </div>-->
        <?php foreach($cluster as $item):?>
            <h2><?php echo $item->territory_name?></h2>
            <p><?php echo ''?></p>
            <input type="hidden" value="<?php echo $item->territory_id?>" name="territory_id"/>
        <?php endforeach?>
        </div>
        <div class="right-panel-body">
            <table class="item-list" width="100%">
                <thead>
                    <tr>
                        <th>Tanggal</th>
                        <th>Nomor Sales Order</th>
                    </tr>
                </thead>
                <tbody class="info">
                    <tr>
                        <td><?php echo date('d F Y', strtotime($so_info->so_date));?></td>
                        <td><?php echo substr("0000000".$so_info->so_id, -8 ); ?></td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>



<div class="panel-wrap" style="height: auto">
	<div class="panel-header-div">Order Information</div>
    
    <div class="panel-body-div">
        <div class="child-panel-body">
        <div class="left-panel-body">
        
            <table class="item-list" width="60%" border="solid black 1px">
                <thead>
                    <tr>
                        <th>Sales ID</th>
                        <th>Sales Name</th>
                    </tr>
                </thead>
                <tbody class="info">
                    <tr>
                        <td><?php echo $so_info->sales_id?></td>
                        <td><?php echo $so_salesName['user_name']?></td>
                    </tr>
                </tbody>

            </table>
        </div>
    </div>
    
    
    
    
                    
    <div class="child-panel-body">
        
            <table class="item-list trans-info" id="table-updateable" width="98%" style="margin-left: 19px;">
                <thead>
                <tr align="center" class="tr-colour3" id="tr_select_all">
                    
                    <th>Partner</th>
                    <th>ICCID</th>
                    <th>Kode MDN</th>
                    <th>Item Group</th>
                    <th>Description</th>
                    <th>Price (Rp.)</th>
                    <th>Discount</th>
                    <th>Amount (Rp.)</th>
                </tr></thead>
                
                <tbody>

                <?php 
                    $amount = 0; $subtotal = 0; $discount = 0;
                    foreach($so_detail as $detail) :
                        $subtotal += ($detail['price']-($detail['price']*$detail['discount']/100));
                        $discount += $detail['discount'];
                    endforeach;
                ?>
                
                    <tr class="termin day-0" style="background-color: #eaef56"><td colspan="8">Pembayaran Cash</td></tr>
                    <tr class="termin day-7" style="background-color: #eaef56"><td colspan="8">Pembayaran Termin 7 Hari</td></tr>
                    <tr class="termin day-14" style="background-color: #eaef56"><td colspan="8">Pembayaran Termin 14 Hari</td></tr>
                    <tr class="termin day-30" style="background-color: #eaef56"><td colspan="8">Pembayaran Termin 30 Hari</td></tr>
                </tbody>
                <tfoot>
                    <tr>
                        <td colspan="7" align="right">Subtotal</td>
                        <td><?php echo 'Rp '.number_format($subtotal, 2, ',', '.')?></td>
                    </tr>
                    <tr>
                        <td colspan="7" align="right">Discount</td>
                        <td><?php echo number_format($so_info->discount, 2, ',', '.') ?></td>
                    </tr>
                    <tr>
                        <td colspan="7" align="right">Total</td>
                        <td><?php echo 'Rp '.number_format($so_info->cash_paid, 2, ',', '.');?></td>
                    </tr>
                    <tr>
                        <td colspan="7" align="right">Cash/Bank</td>
                        <td><?php echo 'Rp '.number_format($so_info->cash_paid, 2, ',', '.')?></td>
                    </tr>
                </tfoot>
            </table>
    </div>
    
    <div class="child-panel-body-2">
        <table class="table-right-panel" width="92%" style="margin-left: 19px; border: none; ">
            <tr style="height: 15px;">
                <td style="text-align: left; font-weight: bold; font-size: 1.3em;">Remark:</td>
                <td width="94%" style="border-bottom: solid #000 1px;"><?php echo $so_info->remark; ?> </td>
            </tr>
        </table>
    </div>
    
        <div class="child-panel-body-2">
        
            <div class="buttons-2" style="margin: 0 auto">
                
                <!-- <input name = "pinttopdf" type="button" value="Print" onclick="printpdf('<?php echo base_url()?>index.php/sales_order/topdf/<?php echo $so_info->so_id?>/<?php echo $so_info->territory_id?>')"/> -->
                <input name = "pinttopdf" type="button" value="Print" onclick="printpdf('<?php echo base_url()?>index.php/sales_order/topdf/<?php echo $this->uri->segment(3)?>/<?php echo $this->uri->segment(4)?>')"/>
            
            </div>

    </div>
    </div>
    
</div>
</form>
<?php
for ($i=0; $i < count($so_detail); $i++) { 
    // $so_detail[$i]["partner"] = htmlentities($so_detail[$i]["partner"]);
    $so_detail[$i]["partner"] = str_replace("'", "&#8217;", $so_detail[$i]["partner"]);
}
?>
<script type="text/javascript">

    function printpdf(tes)
    {
        window.location = tes+'';
        
    }

    $(document).ready(function() {
        $('.termin').hide();
        var so_detail = jQuery.parseJSON('<?php echo json_encode($so_detail);?>');

        $.each(so_detail, function(key, value) {
            // var channel_name = value["partner"].replace("'", "\'");
            var harga = value["price"] - ((value["discount"] * value["price"]) /100);
            prog =  "<tr>"+
                        "<td>"+value["channel_id"]+" | "+value["partner"]+"</td>"+
                        "<td>"+value["iccid"]+"</td>"+
                        "<td>"+value["mdn"]+"</td>"+
                        "<td>"+value["item_group_name"]+"</td>"+
                        "<td>"+value["item_name"]+"</td>"+
                        "<td>Rp. "+digitGrouping(value["price"])+"</td>"+
                        "<td>"+value["discount"]+" %</td>"+
                        "<td>Rp. "+digitGrouping(harga)+"</td>"+
                    "</tr>";
            if(value["top_day"] == 0) {
                $(".day-0").show();
                $(".day-0").after(prog);
            }
            else if(value["top_day"] == 7) {
                $(".day-7").show();
                $(".day-7").after(prog);
            }
            else if(value["top_day"] == 14) {
                $(".day-14").show();
                $(".day-14").after(prog);
            }
            else if(value["top_day"] == 30) {
                $(".day-30").show();
                $(".day-30").after(prog);
            }

        });

    });

function digitGrouping(harga)
{
    price = parseInt(harga);
    price += '';
    x = price.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + '.' + '$2');
    }
    return x1 + x2 + ",00";
}
</script>

